#include "BlendMaterial.h"

Color BlendMaterial::shade(const Scene * scene, const Ray & ray, const IntersectResult & intersect, const TraceState & traceState) const {
	switch (blendType) {
	case BlendMaterial::Add:
		return shade_M1(scene, ray, intersect, traceState) += shade_M2(scene, ray, intersect, traceState);
	case BlendMaterial::Sub:
		return (shade_M1(scene, ray, intersect, traceState) -= shade_M2(scene, ray, intersect, traceState)).clampNegative();
	case BlendMaterial::Multiply:
		return shade_M1(scene, ray, intersect, traceState) *= shade_M2(scene, ray, intersect, traceState);
	case BlendMaterial::Divide:
		return shade_M1(scene, ray, intersect, traceState) /= shade_M2(scene, ray, intersect, traceState);
	case BlendMaterial::Darken:
		return darken(shade_M1(scene, ray, intersect, traceState), shade_M2(scene, ray, intersect, traceState));
	case BlendMaterial::Lighten:
		return lighten(shade_M1(scene, ray, intersect, traceState), shade_M2(scene, ray, intersect, traceState));
	case BlendMaterial::Difference:
		return difference(shade_M1(scene, ray, intersect, traceState), shade_M2(scene, ray, intersect, traceState));
	default:
		return Colors::Black;
	}
}

bool BlendMaterial::isLuminous() const {
	return material1->isLuminous() || material2->isLuminous();
}

bool BlendMaterial::isTransparent() const {
	return material1->isTransparent() || material2->isTransparent();
}

Color BlendMaterial::getTransparentColor(const Scene * scene, const Ray & ray, const IntersectResult & intersect) const {
	return material1->getTransparentColor(scene, ray, intersect) *= material2->getTransparentColor(scene, ray, intersect);
}
